package com.webchat.ugc.messaegqueue.consumer.redis;

import com.webchat.common.enums.messagequeue.MessageQueueEnum;
import com.webchat.common.service.messagequeue.consumer.AbstractRedisQueueConsumer;
import com.webchat.common.util.JsonUtil;
import com.webchat.domain.dto.queue.MallOrderTimeoutMessageDTO;
import com.webchat.ugc.service.mall.MallProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MallProductOrderTimeoutRedisQueueConsumer extends AbstractRedisQueueConsumer<MallOrderTimeoutMessageDTO> {


    @Autowired
    private MallProductOrderService mallProductOrderService;

    @Override
    protected MallOrderTimeoutMessageDTO convert(String s) {

        return JsonUtil.fromJson(s, MallOrderTimeoutMessageDTO.class);
    }

    @Override
    protected MessageQueueEnum getMessageQueue() {

        return MessageQueueEnum.QUEUE_MALL_ORDER_TIMEOUT_MESSAGE;
    }

    @Override
    protected void receive(MallOrderTimeoutMessageDTO data) {

        // 订单支付超时，库存释放真实消费
        mallProductOrderService.doHandlePaymentTimeoutOrder(data.getOrderNo(), data.getSpuId());
    }

    @Override
    protected void error(MallOrderTimeoutMessageDTO data, Exception ex) {

    }

    @Override
    protected int getRetryTimes() {
        return 1;
    }

    @Override
    protected int getBackQueueTimes() {
        return Integer.MAX_VALUE;
    }
}
